package com.sinbader.xiaole.common.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import com.sinbader.xiaole.common.entity.WarehouseMoveDetail;
import com.sinbader.xiaole.common.mapper.WarehouseMoveDetailMapper;
import com.sinbader.xiaole.common.model.params.WarehouseMoveDetailParam;
import com.sinbader.xiaole.common.model.result.WarehouseMoveDetailResult;
import  com.sinbader.xiaole.common.service.WarehouseMoveDetailService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 仓库移货管理明细 服务实现类
 */
@Service
public class WarehouseMoveDetailServiceImpl extends ServiceImpl<WarehouseMoveDetailMapper, WarehouseMoveDetail> implements WarehouseMoveDetailService {

    @Override
    public void add(WarehouseMoveDetailParam param){
        WarehouseMoveDetail entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(WarehouseMoveDetailParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(WarehouseMoveDetailParam param){
        WarehouseMoveDetail oldEntity = getOldEntity(param);
        WarehouseMoveDetail newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public WarehouseMoveDetailResult findBySpec(WarehouseMoveDetailParam param){
        return null;
    }

    @Override
    public List<WarehouseMoveDetailResult> findListBySpec(WarehouseMoveDetailParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(WarehouseMoveDetailParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(WarehouseMoveDetailParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private WarehouseMoveDetail getOldEntity(WarehouseMoveDetailParam param) {
        return this.getById(getKey(param));
    }

    private WarehouseMoveDetail getEntity(WarehouseMoveDetailParam param) {
        WarehouseMoveDetail entity = new WarehouseMoveDetail();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
